package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.dto.StudyReminderDTO;
import com.example.computer_exam_training_sys.service.UserStudyReminderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/reminders")
public class UserStudyReminderController {

    @Autowired
    private UserStudyReminderService reminderService;

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<StudyReminderDTO>> getUserReminders(@PathVariable Long userId) {
        List<StudyReminderDTO> reminders = reminderService.getUserReminders(userId);
        return ResponseEntity.ok(reminders);
    }

    @PostMapping
    public ResponseEntity<StudyReminderDTO> createReminder(@RequestBody StudyReminderDTO reminderDTO) {
        StudyReminderDTO created = reminderService.createReminder(reminderDTO);
        return ResponseEntity.ok(created);
    }

    @PutMapping("/{reminderId}/status")
    public ResponseEntity<StudyReminderDTO> updateReminderStatus(
            @PathVariable Long reminderId,
            @RequestParam Boolean isEnabled) {
        StudyReminderDTO updated = reminderService.updateReminderStatus(reminderId, isEnabled);
        return ResponseEntity.ok(updated);
    }

    @GetMapping("/pending")
    public ResponseEntity<List<StudyReminderDTO>> getPendingReminders() {
        List<StudyReminderDTO> reminders = reminderService.getPendingReminders();
        return ResponseEntity.ok(reminders);
    }

    @GetMapping("/user/{userId}/history")
    public ResponseEntity<List<StudyReminderDTO>> getTriggeredReminders(@PathVariable Long userId) {
        List<StudyReminderDTO> reminders = reminderService.getTriggeredReminders(userId);
        return ResponseEntity.ok(reminders);
    }
} 